package basic.basic_class01;


import basic.untils.ArrayTestUntil;

public class Code_02_SelectionSort {

    // 选择排序
    public static void selectSort(int[] arr) {
        if (arr == null || arr.length < 2) return;
        for (int i = 0; i < arr.length - 1; i++) {
            int minIndex = i;
            for (int j = i + 1; j < arr.length; j++) {
                minIndex = arr[j] >= arr[minIndex] ? minIndex : j;
            }
            swap(arr,minIndex,i);
        }
    }

    public static void selectSort2(int[] arr) {

    }

    // 交换元素
    public static void swap(int[] arr, int i, int j) {
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }

    public static void main(String[] args) {
        int testTime = 500000;  //测试次数
        int maxSize = 10;
        int maxValue = 100;
        boolean succeed = true;
        for (int i = 0; i < testTime; i++) {
            int[] arr = ArrayTestUntil.generateRandomArray(maxSize,maxValue);  //生成随机数组
            int[] arr1 = ArrayTestUntil.copyArray(arr);   //复制数组
            selectSort2(arr);
            ArrayTestUntil.comparator(arr1);
            if(!ArrayTestUntil.isEquals(arr,arr1)){
                System.out.println("手撸：" + arr);
                System.out.println("标准：" + arr1);
                succeed = false;
                break;
            }
        }
        System.out.println(succeed ? "Nice!" : "Fucking Fucked");
    }
}
